package com.cn.bulu.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cn.bulu.constant.PayMethod;
import com.cn.bulu.dao.CustomerWalletRecordDao;
import com.cn.bulu.pojo.CustomerWalletRecord;
import com.cn.bulu.service.CustomerWalletRecordService;
import com.cn.bulu.utils.DateUtils;
import com.cn.bulu.utils.LuKeOrderNoUtil;

/**
* @author liuchaoya E-mail: 1090969255@qq.com
* @version 创建时间：2017年7月5日 下午3:02:24
* 类说明
*/
@Service("CustomerWalletRecordService")
public class CustomerWalletRecordServiceImpl implements CustomerWalletRecordService{
	@Resource
	private CustomerWalletRecordDao customerWalletRecordDao;

	// 插入工人钱包数据库参数插入
	public int insertCustomerWalletRecord(
			Integer customerId,Integer indentId,Integer customerType,Double mainMoney,
			Double addMoney,Double subMoney,Double finalGetMoney,Double finalLostMoney,Double walletRecharge,
			Double walletWithdrawals,Integer type,Integer status,String remark,
			Integer isDelete,String method) {

		CustomerWalletRecord customerWalletRecord = getworkerWalletRecord(customerId, indentId, customerType, mainMoney,
				addMoney, subMoney, finalGetMoney, finalLostMoney, walletRecharge, walletWithdrawals, type, status,
				remark, isDelete, method);

		customerWalletRecordDao.insertCustomerWalletRecord(customerWalletRecord);
		return customerWalletRecord.getCustomerWalletRecordId() == null ? 0 : customerWalletRecord.getCustomerWalletRecordId();
	}

	// 插入数据库对象插入,并返回主键
	public int insertCustomerWalletRecord(CustomerWalletRecord customerWalletRecord) {
		customerWalletRecordDao.insertCustomerWalletRecord(customerWalletRecord);
		return customerWalletRecord.getCustomerWalletRecordId() == null ? 0 : customerWalletRecord.getCustomerWalletRecordId();
	}

	// 封装参数
	private CustomerWalletRecord getworkerWalletRecord(Integer customerId, Integer indentId, Integer customerType,
			Double mainMoney, Double addMoney, Double subMoney, Double finalGetMoney, Double finalLostMoney,
			Double walletRecharge, Double walletWithdrawals, Integer type, Integer status, String remark,
			Integer isDelete, String method) {
		// 参数准备
		CustomerWalletRecord customerWalletRecord = new CustomerWalletRecord();
		// 属性赋值
		customerWalletRecord.setCustomerId(customerId);// workerId 工人id
		customerWalletRecord.setIndentId(indentId == null ? null : indentId);// indentId
		customerWalletRecord.setMainMoney(mainMoney == null ? 0.00 : mainMoney);// mainMoney 本次交易金额主干
		customerWalletRecord.setAddMoney(addMoney == null ? 0.00 : addMoney);// addMoney商家或者个人对订单进行加价悬赏
		customerWalletRecord.setSubMoney(subMoney == null ? 0.00 : subMoney); // subMoney商家或者个人违约扣款
		customerWalletRecord.setFinalGetMoney(finalGetMoney == null ? 0.00 : finalGetMoney);// finalGetMoney本次交易最终得到钱数
		customerWalletRecord.setFinalLostMoney(finalLostMoney == null ? 0.00 : finalLostMoney);// finalLostMoney本次交易最终失去金额
		customerWalletRecord.setWalletRecharge(walletRecharge == null ? 0.00 : walletRecharge); // walletRecharge充值金额
		customerWalletRecord.setWalletWithdrawals(walletWithdrawals == null ? 0.00 : walletWithdrawals);// walletWithdrawals提现
		customerWalletRecord.setType(type);// type 交易类型
		customerWalletRecord.setRecordEndTime(status == 1 ? DateUtils.getDateTime() : "");// recordEndTime交易结束时间
		customerWalletRecord.setRecordBeginTime(DateUtils.getDateTime()); // recordBeginTime交易开始时间
		customerWalletRecord.setStatus(status == 1 ? 1 : 0);// status
		customerWalletRecord.setRemark(remark);// remark交易备注
		customerWalletRecord.setIsDelete(isDelete == 1 ? 1 : 0);// isDelete
		customerWalletRecord.setMethod(method);// method
		customerWalletRecord.setOrderNo(LuKeOrderNoUtil.getWorkerOrderNo(customerId,PayMethod.getMethodIndex(method),type));// orderNo

		return customerWalletRecord;
	}

}
